<template>
  <div class="login_container">
    <div style="text-align:center"><span class="title">合肥市公安局侦查指挥作战平台</span></div>
    <div class="login_box">
      <!-- 图形 -->
      <div class="avatar">
        <img src="../assets/images/u2.png" alt />
      </div>
      <!-- 表单登录 -->
      <el-form ref="loginFormRef" class="login_form" :model="loginForm" :rules="loginRules">
        <el-form-item prop="username">
          <el-input prefix-icon="iconfont icon-user" v-model="loginForm.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input prefix-icon="iconfont icon-3702mima" v-model="loginForm.password" placeholder="请输入密码" type="password"></el-input>
        </el-form-item>
        <el-form-item style="float:right">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import { log } from 'util';
export default {
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      loginRules:{
          username:[
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 2, max: 7, message: '长度在 2 到 7 个字符', trigger: 'blur' }
          ],
          password:[
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, max: 8, message: '长度在 6 到 8 个字符', trigger: 'blur' }
          ]
      }
    };
  },

  methods: {
      //重置表单
      resetForm(){
        //   console.log(this); 
        //利用ref可以拿到表单原件
        this.$refs.loginFormRef.resetFields();
      },
      //登录
      login(){
          this.$refs.loginFormRef.validate(async flag=>{
              // console.log(flag); true
            //校验失败
              if(!flag) return;
              // console.log(flag);  
            // 校验成功
              const res = await this.axios.get('/ynzc/login/login?username=admin&password=123456');
              console.log(res);
              if(res.data.status==200){
                this.$mg.success('登录成功');
                sessionStorage.setItem('token',res.data.token);
                this.$router.push("/home");
                  
              }else{
                this.$mg.error(res.results.data);
                this.$mg.error('登录失败');
              }  
          })
          //  this.$router.push("/home");
      }
  },

  created() {
  }
};
</script>

<style lang='less' scoped>
.login_container {
  width: 100%;
  height: 100%;
  background-color:#121A26;
  .title{
    position: relative;
    top: 50px;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    font-style: normal;
    font-family: "微软雅黑";
  }
  .title1{
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    font-style: normal;
    font-family: "微软雅黑";
  }
  .login_box {
    margin-top: 50px;
    width: 450px;
    height: 300px;
    background: #192332;
    border-radius: 5px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    .avatar {
      width: 130px;
      height: 130px;
      background-color: #121A26;
      border-radius: 50%;
      // border: 1px solid #121A26;
      padding: 10px;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color:#121A26;
      }
    }
    .login_form {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
    }
  }
}
</style>
